package com.it.gw.modules.station.adapter

import android.annotation.SuppressLint
import android.content.Context
import android.util.Log
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.it.data.network.rsp.QuaTypeShellVo
import com.it.gw.databinding.ItemOprationQuestionBinding


class QuaTypeShellDetailAdapter(
    var context: Context,
    var listener: ((QuaTypeShellVo) -> Unit)? = null,
    var queDealEnable:Boolean? = true,
    var datas: List<QuaTypeShellVo>
) : RecyclerView.Adapter<QuaTypeShellDetailAdapter.ViewHolder>() {
    companion object {
        const val TAG = "QuaTypeShellAdapter"
    }

    override fun onCreateViewHolder(
        parent: ViewGroup,
        viewType: Int
    ): ViewHolder {
        val binding = ItemOprationQuestionBinding.inflate(LayoutInflater.from(parent.context))
        return ViewHolder(binding)
    }


    override fun onBindViewHolder(holder: ViewHolder, @SuppressLint("RecyclerView") position: Int) {
        val data = datas[position]
        Log.d(TAG, "onBindViewHolder: $data")
        holder.binding.name.text = data.data_Name
        if (data.selected) {
            holder.binding.ivCheck.setImageResource(com.it.gw.R.drawable.icon_selected)
        } else {
            holder.binding.ivCheck.setImageResource(com.it.gw.R.drawable.icon_un_select)
        }
        holder.binding.root.setOnClickListener {
            if(queDealEnable==true){
                listener?.invoke(data)
            }

        }


    }

    override fun getItemCount() = datas.size

    class ViewHolder(val binding: ItemOprationQuestionBinding) :
        RecyclerView.ViewHolder(binding.root)
}